#pragma once
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include <cstdio>
#include <unistd.h>
#include <fcntl.h>
#include "INETADDR.hpp"

enum ExitCode
{
    OK = 0,
    USAGE_ERRO,
    SOCKET_ERRO,
    BIND_ERRO,
    LISTEN_ERRO,
    ACCEPT_ERRO,
    CONNECT_ERRO,
    FORK_ERRO,
    RECV_ERRO,
    OPEN_ERRO,
    EPOLL_CREATE_ERRO,
    FCNTL_ERRO
};
void SetNoBlock(int sockfd)
{
    int fl = fcntl(sockfd,F_GETFL);
    if(fl < 0)
    {
        perror("fcntl F_GETFL");
        exit(FCNTL_ERRO);
    }
    int ret = fcntl(sockfd,F_SETFL,fl | O_NONBLOCK);
    if(ret < 0)
    {
        perror("fcntl F_SETFL");
        exit(FCNTL_ERRO);
    }
}